//------------------------------------------------------------------------------
/// This class was copied directly from the VSTO designer sources.  It is
/// an internal class in Microsoft.VisualStudio.OfficeTools.Designer.dll                                                             
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;

///<devdoc>
/// This class provides a useful base class for creating specialized PropertyDescriptors.  It delegates
/// all calls through PropertyDescriptor to the inner property descriptor (passed to the .ctor).  This
/// allows derived classes to only override the properties/methods that are interesting, without the need
/// to reimplement the delegation for every other property/method.
///</devdoc>
namespace Ferpect.GameComponents.Design
{
    public class PropertyDescriptorWrapper : PropertyDescriptor
    {
        private PropertyDescriptor innerPropertyDescriptor;

        public PropertyDescriptorWrapper(PropertyDescriptor innerPropertyDescriptor)
            : this(innerPropertyDescriptor, new Attribute[0])
        {
        }

        public PropertyDescriptorWrapper(PropertyDescriptor innerPropertyDescriptor, Attribute[] attributes)
            : base(innerPropertyDescriptor, attributes)
        {
            if (innerPropertyDescriptor == null) throw new ArgumentNullException("innerPropertyDescriptor");
            this.innerPropertyDescriptor = innerPropertyDescriptor;
        }

        // Access to innerPropertyDescriptor for derived classes.  Property is read-only and .ctor
        // ensures it is non-null, so derived classes never have to check.
        protected PropertyDescriptor InnerDescriptor
        {
            get
            {
                return this.innerPropertyDescriptor;
            }
        }

        // MemberDescriptor overrides

        public override string Name { get { return this.innerPropertyDescriptor.Name; } }
        public override string DisplayName { get { return this.innerPropertyDescriptor.DisplayName; } }

        // PropertyDescriptor overrides

        public override Type ComponentType { get { return this.innerPropertyDescriptor.ComponentType; } }
        public override TypeConverter Converter { get { return this.innerPropertyDescriptor.Converter; } }
        public override bool IsLocalizable { get { return this.innerPropertyDescriptor.IsLocalizable; } }
        public override bool IsReadOnly { get { return this.innerPropertyDescriptor.IsReadOnly; } }
        public override Type PropertyType { get { return this.innerPropertyDescriptor.PropertyType; } }
        public override void AddValueChanged(object component, EventHandler handler) { this.innerPropertyDescriptor.AddValueChanged(component, handler); }
        public override bool CanResetValue(object component) { return this.innerPropertyDescriptor.CanResetValue(component); }
        public override PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter) { return this.innerPropertyDescriptor.GetChildProperties(instance, filter); }
        public override object GetEditor(Type editorBaseType) { return this.innerPropertyDescriptor.GetEditor(editorBaseType); }
        public override object GetValue(object component) { return this.innerPropertyDescriptor.GetValue(component); }
        public override void RemoveValueChanged(object component, EventHandler handler) { this.innerPropertyDescriptor.RemoveValueChanged(component, handler); }
        public override void ResetValue(object component) { this.innerPropertyDescriptor.ResetValue(component); }
        public override void SetValue(object component, object value) { this.innerPropertyDescriptor.SetValue(component, value); }
        public override bool ShouldSerializeValue(object component) { return this.innerPropertyDescriptor.ShouldSerializeValue(component); }
        public override bool SupportsChangeEvents { get { return this.innerPropertyDescriptor.SupportsChangeEvents; } }
    }
}

